'use strict';

var express = require('express')
  , app = express()
  , http = require('http')
  , path = require('path');
var host = process.env.VCAP_APP_HOST || 'localhost';
var port = process.env.VCAP_APP_PORT || '3000';

app.use(require('body-parser').urlencoded({extended: true}))
app.use(express.static(path.join(__dirname, 'public')));
// app.use('mm', express.static(path.join(__dirname, 'views')));

app.use('/', require('./routes'));
app.use('/home', require('./routes/home'));
app.use('/other', require('./routes/other'));

var server = http.createServer(app);
var io = require('socket.io')(server);
io.on('connection', function (socket) {

	socket.on('wx', function(data){
		var wx = require('./lib/wx')(data.fiveele);

		socket.emit('wxreturn', { res:wx });
		
	});

});

server.listen(port, function(){
  	console.log("Server running at http://" + host + ":" + port + "/");
});
// var server = app.listen(port, function(){
// 	console.log("Server running at http://" + host + ":" + port + "/");
// });
